 // 导入WebSocket包
 const WebSocket = require('ws');

 // 创建WebSocket服务器监听3000端口
 const wss = new WebSocket.Server({ port: 3001 });
 
 // 监听连接事件，当客户端连接到WebSocket服务器时触发
 wss.on('connection', function connection(ws) {
   // 每秒向前端发送消息
   const timer = setInterval(() => {
     ws.send(JSON.stringify({
        type: 'roommsg',
        ly: 1,
        msg: '[{"type":"text","msg":"【群主】"},{"type":"pic","url":"http:\\/\\/tc.feixunline.cn\\/view.php\\/23a702f820d8600875c46eef5a23b61c.bmp"}]',
        mb: 556,
        uid: 0,
        timestamp: '1709262130'
      }));
   }, 1000);
 
   // 监听前端发过来的消息，并在控制台输出消息内容
   ws.on('message', function incoming(message) {
     // 获取查询参数
    //  const queryParams = conn.path.split('?')[1];
    //  console.log('query', queryParams)
    //  console.log('received: %s', message);
   });
 
   // 监听断开连接事件，清除计时器
   ws.on('close', function close() {
     clearInterval(timer);
   });
 });